﻿using JeremyAnsel.DirectX.D2D1;
using System;
using System.Windows.Forms;

namespace MainForm
{
    public partial class CountdownBar : Panel
    {
        public CountdownBar()
        {
            InitializeComponent();
            this.Init();
        }
        
        protected override void OnPaint(PaintEventArgs pe)
        {
            base.OnPaint(pe);
        }
        protected System.Threading.Timer Timer { get; set; }
        protected D2D1Factory D2D1Factory { get; set; }
        protected D2D1RenderTarget D2D1RenderTarget { get; set; }
        protected D2D1SolidColorBrush D2d1SolidBrush { get; set; }
        protected void Init()
        {
            this.D2D1Factory = D2D1Factory.Create(D2D1FactoryType.SingleThreaded);
            this.D2D1RenderTarget = this.D2D1Factory.CreateHwndRenderTarget(
                new D2D1RenderTargetProperties(),
                new D2D1HwndRenderTargetProperties(
                    this.Handle,
                    new D2D1SizeU(Convert.ToUInt32(this.Width), Convert.ToUInt32(this.Height)),
                    D2D1PresentOptions.Immediately
                )
            );
            this.D2d1SolidBrush = this.D2D1RenderTarget.CreateSolidColorBrush(new D2D1ColorF(255, 181, 197));
        }
        public void Start()
        {
            this.D2D1RenderTarget.BeginDraw();
            this.D2D1RenderTarget.Clear();
            D2D1RectF rectF = new D2D1RectF(0, 0, this.Width, this.Height);
            this.D2D1RenderTarget.DrawRectangle(rectF, this.D2d1SolidBrush);
            this.D2D1RenderTarget.EndDraw();
        }
        ~CountdownBar()
        {
            this.D2d1SolidBrush.Dispose();
            this.D2D1RenderTarget.Dispose();
            this.D2D1Factory.Dispose();
            if (this.Timer != null)
            {
                this.Timer.Dispose();
            }
        }
    }
}
